<?php
// +----------------------------------------------------------------------
// | Created by Sublime: [ Conqweal ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021~20223[chenjia] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.99dn.cn
// +----------------------------------------------------------------------
// | Author: Conqweal <150672834@qq.com>
// +----------------------------------------------------------------------
// | Date: 2021/12/22 0026
// +----------------------------------------------------------------------
// | Description:金币接口
// +----------------------------------------------------------------------

namespace app\api\controller;

use app\Api; 
use app\api\model\UserMoneyLog as cmodel; 
use think\facade\Db;
use think\facade\Cache;
use think\facade\Validate;
use app\ApiController;
use support\Request;

class IntegralController extends ApiController
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

    }

    
     

    /**
     * 充值提现列表
     * @param  [type] $token [登录token]
     * @return [type]        [json数据]
     */
    public function index($token)
    {
        
        $u_id            = $this->auth->u_id;
         //支付状态
         //过帐类型
        $tmp        = cmodel::getOpType();         
        $op_type_options = output_select($tmp, '');  

        $request = request();
           $limit = $request->get('limit', 10);

        $w[] = ['a.u_id', '=', $u_id  ];

        if ($request->get('memo')) {
            $w[] = ['a.memo', 'like', '%' . $request->get('memo') . '%'];

        }      
      

        if ($request->get('op_type')) {
            $w[] = ['a.op_type', '=', $request->get('op_type')];

        }        

        $q = cmodel::alias('a')->where($w);
        $q->order("a.id","desc");

        $ls     = $q->paginate(['list_rows' => $limit, 'request' => $request->all()]);
        
        $res    = $ls->items();
        $op_type = cmodel::getOpType();
        $res    = array_map(function ($v) use ($op_type) { 
            $v->money = $v->plus-$v->reduce;          
            $v->op_type_txt = $op_type[$v->op_type];
            $v->memo  = $v->memo?:$v->op_type_txt;
         
            return $v;
        }, $res);

        $data['ls'] = $res;
        
        $data['total'] = $ls->total();
        $data['options'] = [
            'op_type_options'=>$op_type_options,
        ];
         
        return $this->success(__('Operation successful'), $data);
    }
    
    

     
}